/**
 *
 * Copyright 2018 iQIYI.com
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 */
package com.iqiyi.halberd.liteapp.api.provider;

import android.support.annotation.Nullable;
import android.util.Log;

import com.iqiyi.halberd.liteapp.LiteAppFragmentActivity;
import com.iqiyi.halberd.liteapp.view.LiteAppBaseActivity;

/**
 * Created by xujiajia_sx on 2017/12/4.
 *
 */

public class LiteAppErrorProvider {
    private final static String TAG = LiteAppErrorProvider.class.getName();

    public interface OnErrorListener {
        void onError(String description ,@Nullable LiteAppBaseActivity errorActivity);
    }
    private static OnErrorListener onErrorListener;

    public static void setOnErrorListener(OnErrorListener onErrorListener) {
        LiteAppErrorProvider.onErrorListener=onErrorListener;
    }

    public static void error(String description) {
        Log.d(TAG, "LiteAppErrorProvider.error description:"+description);
        if (onErrorListener != null) {
            if(LiteAppBaseActivity.topInstance == null){
                onErrorListener.onError(description, null);
                return;
            }
            onErrorListener.onError(description, LiteAppFragmentActivity.topInstance.get());
        }
    }
}
